package myself;

public class SortDemo {
	
	public static void main(String[] args) {
		
		int[] arr = new int[] {34,5,22,-98,6,-76,0,-3};
		//冒泡排序
//		for(int i=0;i<arr.length-1;i++) {
//			for(int j = 0;j<arr.length-i-1;j++) {
//				if(arr[j] > arr[j+1]) {
//					int temp = arr[j];
//					arr[j] = arr[j+1];
//					arr[j+1] = temp;
//				}
//			}
//		}
//		for(int i=0;i<arr.length;i++) {
//			System.out.print(arr[i]+" ");
//		}
		
		//二分查找
		int desc = 22;
		int start = 0;
		int end = arr.length-1;
		boolean isFlag = true;
		while(start <= end) {
			int middle = (end - start)/2;
			
			if(arr[middle] == desc) {
				System.out.println("找到了 "+middle);
				isFlag = false;
				break;
			}else if(arr[middle] > desc) {
				end = middle - 1;
			}else {
				start = middle + 1;
			}
			
		}
		while(isFlag) {
			System.out.println("未找到");
		}
		
	
		
	}
	
}
